﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Documents;
using Avalonia.Media;
using ExcelDataReader;
using Microsoft.Data.Sqlite;
using Nlnet.Avalonia.Controls;
using OfficeOpenXml;
using 畜牧业审核程序国产.Models.ComparisonOutcome;
using 畜牧业审核程序国产.Models.ToolsClass;
using 畜牧业审核程序国产.ViewModels;
//using Color = Avalonia.Media.Color;
using Color = System.Drawing.Color;
using Icon = MsBox.Avalonia.Enums.Icon;

using System.Linq.Expressions;

namespace 畜牧业审核程序国产.Models
{
    internal class AuditFunc
    {
        //public static bool ExecuteGetDataCommandNow()
        //{

        //}

        public static FuncOutCome Audit(string strYearNow, string strSeasonNow, string strYearPre, string strSeasonPre,
            string strYearYOY, string strSeasonYOY, IProgress<int> progress)
        {
            MyDataFolderOperator.CreateOrCheckAuditProgramFolderExist(); //检查审核程序文件夹是否已经建立了,要把审核结果输出到这个文件夹
             
            // MyDBOperator auditOperator = new MyDBOperator();
            //改用单例模式
            var auditOperator = MyDBOperator.DBOperatorInstance;
            #region 设置好报表平台
            string[] allBeAuditTablesNamesA = new[] { "A209", "A210", "A211", "A212","A406" };
            //这里要不要做个判断,如果有一套表,优先选择一套表,如果没有一套表,再使用统计云
            string platformNow = "统计云";
            string platformPre = "统计云";
            string platformYOY = "一套表";
           
            List<string> unexistsUnionTablesNow =
                auditOperator.CheckTablesExist(new string[]{ "统计云" + strYearNow + strSeasonNow + "A209","统计云" + strYearNow + strSeasonNow + "A210",
                       "统计云" + strYearNow + strSeasonNow + "A211","统计云" + strYearNow + strSeasonNow + "A212"});
            if (unexistsUnionTablesNow.Count == 4)
            {
                platformNow = "一套表";
            }

            List<string> unexistsUnionTablesPre =
               auditOperator.CheckTablesExist(new string[]{ "统计云" + strYearPre + strSeasonPre + "A209","统计云" + strYearPre + strSeasonPre + "A210",
                       "统计云" + strYearPre + strSeasonPre + "A211","统计云" + strYearPre + strSeasonPre + "A212"});
            if (unexistsUnionTablesPre.Count==4)
            {
                platformPre = "一套表";
            }
            List<string> unexistsUnionTablesYOY =
              auditOperator.CheckTablesExist(new string[]{ "统计云" + strYearYOY + strSeasonYOY + "A209","统计云" + strYearYOY + strSeasonYOY + "A210",
                       "统计云" + strYearYOY + strSeasonYOY + "A211","统计云" + strYearYOY + strSeasonYOY + "A212"});
            if (unexistsUnionTablesPre.Count == 4)
            {
                platformYOY = "一套表";
            }
            //List<Tuple<string, string, string>> allBeAuditNamesTuple = new List<Tuple<string, string, string>>();
            //allBeAuditNamesTuple.Add(new Tuple<string, string, string>(platformNow + strYearNow + strSeasonNow + "A209", platformNow + strYearPre + strSeasonPre + "A209", "一套表" + strYearNow + strSeasonNow + "A406"));
            //allBeAuditNamesTuple.Add(new Tuple<string, string, string>(platformNow + strYearNow + strSeasonNow + "A210", platformNow + strYearPre + strSeasonPre + "A210", "一套表" + strYearNow + strSeasonNow + "A406"));
            //allBeAuditNamesTuple.Add(new Tuple<string, string, string>(platformNow + strYearNow + strSeasonNow + "A211", platformNow + strYearPre + strSeasonPre + "A211", "一套表" + strYearNow + strSeasonNow + "A406"));
            //allBeAuditNamesTuple.Add(new Tuple<string, string, string>(platformNow + strYearNow + strSeasonNow + "A212", platformNow + strYearPre + strSeasonPre + "A212", "一套表" + strYearNow + strSeasonNow + "A406"));
            //allBeAuditNamesTuple.Add(new Tuple<string, string, string>("一套表" + strYearNow + strSeasonNow + "A406", "一套表" + strYearPre + strSeasonPre + "A406", "空"));


            //if (Convert.ToInt16(strYearNow.Substring(0, 4)) < 2025)
            //{
            //    platformNow = platformPre = platformYOY = "一套表";
            //    List<string> unexistsUnionTables =
            //     auditOperator.CheckTablesExist(new string[]{ platformNow + strYearNow + strSeasonNow + "A209",platformNow + strYearNow + strSeasonNow + "A209",
            //            platformNow + strYearNow + strSeasonNow + "A211",platformNow + strYearNow + strSeasonNow + "A212"});
            //    if (unexistsUnionTables.Count==4)
            //    {
            //        platformNow = "统计云";
            //    }

            //}
            //else if (Convert.ToInt16(strYearNow.Substring(0, 4)) == 2025)
            //{
            //    platformNow = platformPre = "统计云";
            //    platformYOY = "一套表";
            //}
            //else
            //{
            //    platformNow = platformPre = platformYOY = "统计云";
            //}






            //string[] allBeAuditNames = new[]
            //{
            //    $"一套表{strYearNow}{strSeasonNow}A209", $"一套表{strYearNow}{strSeasonNow}A210",
            //    $"一套表{strYearNow}{strSeasonNow}A211", $"一套表{strYearNow}{strSeasonNow}A212",
            //    $"一套表{strYearNow}{strSeasonNow}A406"
            //};

            #endregion
            FuncOutCome auditFuncOutCome = new FuncOutCome();
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            //下面三个变量为进度条准备的
            int processedFiles = 0;
            int totalFiles = 5;
            int percentage = 0;
            try
            {
                using (var excelPackage = new ExcelPackage()) //注意openxm下标也是从1开始
                {
                    //try
                    //{
                    //foreach (string tableNameA in allBeAuditTablesNamesA)
                    //{
                    //    string withYearAndSeasonTableNameNow = platformNow + strYearNow + strSeasonNow + tableNameA;
                    //    string withYearAndSeasonTableNamePre = platformPre + strYearPre + strSeasonPre + tableNameA;
                    //    string withYearAndSeasonTableNameYOY = platformYOY + strYearYOY + strSeasonYOY + tableNameA;
                    foreach (string tableNameA in allBeAuditTablesNamesA)
                    {
                        string? withYearAndSeasonTableNameNow =null;
                        string? withYearAndSeasonTableNamePre = null;
                        string? withYearAndSeasonTableNameYOY = null;
                        if (tableNameA.Equals("A406"))
                        {
                            withYearAndSeasonTableNameNow = "一套表" + strYearNow + strSeasonNow + tableNameA;
                            withYearAndSeasonTableNamePre = "一套表" + strYearPre + strSeasonPre + tableNameA;
                            withYearAndSeasonTableNameYOY = "一套表" + strYearYOY + strSeasonYOY + tableNameA;
                        }
                        else
                        {
                            withYearAndSeasonTableNameNow = platformNow + strYearNow + strSeasonNow + tableNameA;
                            withYearAndSeasonTableNamePre = platformPre + strYearPre + strSeasonPre + tableNameA;
                            withYearAndSeasonTableNameYOY = platformYOY + strYearYOY + strSeasonYOY + tableNameA;
                        }

                        //先判断这张表有没有在数据库里面,如果没有的话,就查找下一张表是否在数据库里面
                        bool isWithYearAndSeasonTableExists =
                            auditOperator.CheckIfTableExists(withYearAndSeasonTableNameNow);
                        if (isWithYearAndSeasonTableExists == false)
                        {
                            processedFiles++;
                            percentage = (int)((double)processedFiles / totalFiles * 100);
                            progress.Report(percentage);
                            auditFuncOutCome.FuncOutComeInfoArgs +=
                                $"本地数据库中不存在{withYearAndSeasonTableNameNow},因此该表的表内关系未审核       " + Environment.NewLine;
                            //auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.NullError;
                            auditFuncOutCome.Icon = Icon.Warning;
                            continue;
                        }
                        //如果该表存在,先进行表内关系审核
                        //先删除查询用表

                        auditOperator.DeleteQueryTableThenCreateNewQueryTable(withYearAndSeasonTableNameNow);
                        //正式开始审核了

                        var shtAuditOutcome = excelPackage.Workbook.Worksheets.Add($"{withYearAndSeasonTableNameNow}审核结果");

                        #region 表内关系审核

                        //先进行表内逻辑关系审核
                        //MyDBOperator auditThisSeasonSelfOperator = new MyDBOperator();改用单例模式
                        var auditThisSeasonSelfOperator = MyDBOperator.DBOperatorInstance;
                        string auditFormulaTableNameInDB =
                            $"审核公式{withYearAndSeasonTableNameNow.Substring(withYearAndSeasonTableNameNow.Length - 4, 4)}";//审核公式表名称,例如审核公式A209
                        //获取正在审核的这张表的第一行的市代码的值
                        string CityCode = auditThisSeasonSelfOperator.GetValueOfAssignColumnNameInFirstRow(withYearAndSeasonTableNameNow, "市代码");
                        //看看审核公式的表里有没有这个市的专属公式
                       // var allExclusiveFormula = auditThisSeasonSelfOperator.GetDataTable("select ")
                        string sqlToGetAllAuditFormula =
                            $"select * from {auditFormulaTableNameInDB} where 表间关系 = '表内' and (是否启用 ='是' or ( 是否启用 = '否' and 专属地市 like '%{CityCode}%' )) order by 严重度";
                        DataTable dtOfAllFormula =
                            auditThisSeasonSelfOperator.GetDataTable(sqlToGetAllAuditFormula); //不会为空的
                        if (dtOfAllFormula.Rows.Count == 0)
                        {
                            auditFuncOutCome.FuncOutComeInfoArgs += $"{auditFormulaTableNameInDB}不存在表内审核的公式!";
                        }

                        shtAuditOutcome.Cells[1, 1].Value = "审核原因说明(请勿在后面的列增加内容,有可能导致新旧审核结果过录失败)";
                        int startRow = 2; // 第一个 DataTable 从第二行开始写入
                        string oneSingleAuditFormula = null;
                        string oneSingleAuditFormulaName = null;

                        for (int i = 0; i < dtOfAllFormula.Rows.Count; i++)
                        {
                            try
                            {
                                DataRow row = dtOfAllFormula.Rows[i];
                                //string oneSingleAuditFormula = row["sql语句"].ToString();
                                oneSingleAuditFormulaName = row["审核公式名称"].ToString();
                                oneSingleAuditFormula = row["sql语句"].ToString();
                                DataTable dtOfOneAuditFormulaOutcome =
                                    auditThisSeasonSelfOperator.GetDataTable(oneSingleAuditFormula);
                                if (dtOfOneAuditFormulaOutcome.Rows.Count != 0)//如果这里修改成is not null,下面的tryctch就不会抓到错误
                                {
                                    // 将审核结果写入Excel
                                    //先写入审核公式

                                    shtAuditOutcome.Cells[startRow, 2].Value = "类型:" + row["表间关系"].ToString(); //shtAuditOutcome.Cells[startRow, 2].Style.WrapText = true;
                                    shtAuditOutcome.Cells[startRow + 1, 2].Value = "严重度:" + row["严重度"].ToString();
                                    shtAuditOutcome.Cells[startRow + 2, 2].Value = "审核公式:" + row["审核公式名称"].ToString();
                                    shtAuditOutcome.Cells[startRow + 3, 2].Value = "说明:" + row["审核公式说明"].ToString();
                                    if (row["严重度"].ToString().Contains("强制性"))
                                    {
                                        shtAuditOutcome.Cells[startRow, 2].Style.Font.Color.SetColor(Color.Red);
                                        shtAuditOutcome.Cells[startRow + 1, 2].Style.Font.Color.SetColor(Color.Red);
                                        shtAuditOutcome.Cells[startRow + 2, 2].Style.Font.Color.SetColor(Color.Red);
                                        shtAuditOutcome.Cells[startRow + 3, 2].Style.Font.Color.SetColor(Color.Red);
                                    }
                                    else
                                    {
                                        shtAuditOutcome.Cells[startRow, 2].Style.Font.Color.SetColor(Color.Blue);
                                        shtAuditOutcome.Cells[startRow + 1, 2].Style.Font.Color.SetColor(Color.Blue);
                                        shtAuditOutcome.Cells[startRow + 2, 2].Style.Font.Color.SetColor(Color.Blue);
                                        shtAuditOutcome.Cells[startRow + 3, 2].Style.Font.Color.SetColor(Color.Blue);
                                    }

                                    //先写入表头,即县\乡\村这些内容
                                    for (int colCountOfdtOfOneAuditFormulaOutcome = 0;
                                         colCountOfdtOfOneAuditFormulaOutcome < dtOfOneAuditFormulaOutcome.Columns.Count;
                                         colCountOfdtOfOneAuditFormulaOutcome++)
                                    {
                                        shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2]
                                            .Value = dtOfOneAuditFormulaOutcome
                                            .Columns[colCountOfdtOfOneAuditFormulaOutcome].ColumnName;
                                        shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style
                                            .Font.Size = 12;
                                        shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style
                                           .WrapText = true;
                                        shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style.Font.Bold = true;
                                        //shtAuditOutcome.Cells[startRow, colCountOfdtOfOneAuditFormulaOutcome + 2].Style.Font.Color 
                                    }

                                    //写入数据
                                    for (int rowCountOfdtOfOneAuditFormulaOutcome = 0;
                                         rowCountOfdtOfOneAuditFormulaOutcome < dtOfOneAuditFormulaOutcome.Rows.Count;
                                         rowCountOfdtOfOneAuditFormulaOutcome++)
                                    {
                                        for (int colCountOfdtOfOneAuditFormulaOutcome = 0;
                                             colCountOfdtOfOneAuditFormulaOutcome <
                                             dtOfOneAuditFormulaOutcome.Columns.Count;
                                             colCountOfdtOfOneAuditFormulaOutcome++)
                                        {
                                            shtAuditOutcome.Cells[startRow + rowCountOfdtOfOneAuditFormulaOutcome + 5,
                                                    colCountOfdtOfOneAuditFormulaOutcome + 2].Value =
                                                dtOfOneAuditFormulaOutcome.Rows[rowCountOfdtOfOneAuditFormulaOutcome][
                                                    colCountOfdtOfOneAuditFormulaOutcome];
                                        }
                                    }

                                    // 更新 startRow 为当前写入的最后一行的下一行
                                    startRow += dtOfOneAuditFormulaOutcome.Rows.Count + 5;


                                    // 写入表头
                                    //for (int col = 0; col < dtOfOneAuditFormulaOutcome.Columns.Count; col++)
                                    //{
                                    //    shtAuditOutcome.Cells[1, col + 1].Value = dtOfOneAuditFormulaOutcome.Columns[col].ColumnName;
                                    //}
                                }
                            }
                            catch (Exception ex)
                            {
                                StaticLogger.SystemError($"执行{auditFormulaTableNameInDB}中的{oneSingleAuditFormulaName}公式时出错,错误信息为{ex.Message}");
                                auditFuncOutCome.FuncOutComeInfoArgs += $"执行{auditFormulaTableNameInDB}中的{oneSingleAuditFormulaName}公式时出错,错误信息为{ex.Message}" + Environment.NewLine;
                                auditFuncOutCome.Icon = Icon.Warning;
                                continue;
                            }
                        }



                        //先在这里进行列宽度设置,不在下面设置了
                        int totalColumns = shtAuditOutcome.Dimension.End.Column;
                        for (int i = 1; i <= totalColumns; i++)
                        {
                            shtAuditOutcome.Columns[i].Width = 20;
                        }
                        #endregion

                        //进行环比关系的审核
                        //判断环比用表在不在
                        bool isPreSeaonTableExists = auditOperator.CheckIfTableExists(withYearAndSeasonTableNamePre);

                        if (isPreSeaonTableExists)//如果环比用表存在
                        {
                            //如果环比用表存在
                            //先删除原来的环比用表
                            auditOperator.DeleteQoQTableThenCreateNewQoQTable(withYearAndSeasonTableNamePre);

                            //审核公式表名称
                            auditFormulaTableNameInDB = $"审核公式{tableNameA}";
                            SingleAudit(auditFormulaTableNameInDB, CityCode, "环比", shtAuditOutcome, ref startRow, auditFuncOutCome);
                            SingleAudit(auditFormulaTableNameInDB, CityCode,"与上季度逻辑", shtAuditOutcome, ref startRow, auditFuncOutCome);
                        }
                        else
                        {
                            auditFuncOutCome.FuncOutComeInfoArgs +=
                                $"本地数据库中不存在{withYearAndSeasonTableNameNow}的上一季度数据,因此{tableNameA}表的环比和跟上季度联审的公式都未审核" +
                                Environment.NewLine;
                           // auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.LosePreSeasonError;
                            auditFuncOutCome.Icon = Icon.Warning;

                        }



                        //进行规模户与全面关系的审核
                        if (tableNameA.Equals("A406"))
                        {
                            processedFiles++;
                            percentage = (int)((double)processedFiles / totalFiles * 100);
                            progress.Report(percentage);
                            auditFuncOutCome.FuncOutComeInfoArgs +=
                                $"{withYearAndSeasonTableNameNow}完成审核时间:{DateTime.Now.ToString()}         " + Environment.NewLine;
                            continue;
                        }
                        bool isA406TableExists = auditOperator.CheckIfTableExists("一套表" + strYearNow + strSeasonNow + "A406");
                        if (isA406TableExists)
                        {
                            DataTable dtOf全面用表 =
                                auditOperator.GetDataTable(
                                    "select * from 一套表" + strYearNow + strSeasonNow + "A406");
                            if (dtOf全面用表==null  && dtOf全面用表.Rows.Count==0)
                            {
                                auditFuncOutCome.FuncOutComeInfoArgs += $"本地数据库中的" + strYearNow + strSeasonNow + $"A406表中没有数据,因此{tableNameA}表的规模户跟全面数据对比的公式都未审核" +
                                                                        Environment.NewLine;
                                processedFiles++;
                                percentage = (int)((double)processedFiles / totalFiles * 100);
                                progress.Report(percentage);
                                auditFuncOutCome.Icon = Icon.Warning;
                                continue;
                            }
                            //如果A406表存在
                            auditFormulaTableNameInDB = $"审核公式{tableNameA}";
                            //先删除原来的全面用表
                            auditOperator.DeleteTotalTableThenCreateNewTotalTable("一套表" + strYearNow + strSeasonNow + "A406");
                            SingleAudit(auditFormulaTableNameInDB, CityCode,"规模户与全面", shtAuditOutcome, ref startRow, auditFuncOutCome);
                            processedFiles++;
                            percentage = (int)((double)processedFiles / totalFiles * 100);
                            progress.Report(percentage);
                            auditFuncOutCome.FuncOutComeInfoArgs +=
                                $"{withYearAndSeasonTableNameNow}完成审核时间:{DateTime.Now.ToString()}         " + Environment.NewLine;
                        }
                        else
                        {
                            auditFuncOutCome.FuncOutComeInfoArgs += $"本地数据库中不存在一套表"  + strYearNow + strSeasonNow + $"A406表,因此{tableNameA}表的规模户跟全面数据对比的公式都未审核" +
                                Environment.NewLine;
                            processedFiles++;
                            percentage = (int)((double)processedFiles / totalFiles * 100);
                            progress.Report(percentage);
                            //auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.LoseA406Error;
                            auditFuncOutCome.Icon = Icon.Warning;
                            continue;
                        }




                        ////设置列宽度,在上面设置了
                        //int totalColumns = shtAuditOutcome.Dimension.End.Column;
                        //for (int i = 1; i <= totalColumns; i++)
                        //{
                        //    shtAuditOutcome.Columns[i].Width = 20;
                        //}

                    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    Log.Error($"审核时出错,出错的内容为{ex.Message}" + Environment.NewLine);
                    //    percentage = 100;
                    //    progress.Report(percentage);
                    //    auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.Error;
                    //    auditFuncOutCome.FuncOutComeInfoArgs = ex.Message;
                    //    return auditFuncOutCome;


                    //}
                    FileInfo excelFileInfo = new FileInfo(Path.Combine(
                        MyDataFolderOperator.AuditOutcomeFolderPathInAuditProgramFolder,
                        $"{strYearNow}{strSeasonNow}审核结果{DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}.xlsx"));
                    excelPackage.SaveAs(excelFileInfo);
                    if (auditFuncOutCome.Icon != Icon.Warning)
                    {
                        auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.Success;
                        auditFuncOutCome.Icon = Icon.Success;
                    }

                    return auditFuncOutCome;
                }
            }
            catch (Exception ex)
            {
                StaticLogger.SystemError($"执行审核时出错,出错的内容为{ex.Message}" + Environment.NewLine);//总感觉这里获取到的信息还差点意思
                percentage = 100;
                progress.Report(percentage);
                //auditFuncOutCome.FuncSuccessCode = FuncOutComeCodeType.Error;
                auditFuncOutCome.FuncOutComeInfoArgs = ex.Message;
                auditFuncOutCome.Icon= Icon.Error;
                return auditFuncOutCome;
            }
        }

        private static void SingleAudit(string auditFormulaTableNameInDB,string CityCode, string logicalRelation,
            ExcelWorksheet shtAuditOutcome, ref int startRow, FuncOutCome auditOutcome)
        {
            string singleAuditOutCome = null;
            //MyDBOperator auditOperator = new MyDBOperator();改用单例模式
            var auditOperator = MyDBOperator.DBOperatorInstance;
            string sqlToGetAllAuditFormula =
                $"select * from {auditFormulaTableNameInDB} where 表间关系 = '{logicalRelation}' and (是否启用='是' or ( 是否启用 = '否' and 专属地市 like '%{CityCode}%' )) ORDER BY 严重度";
            DataTable dtOfAllFormula =
                auditOperator.GetDataTable(sqlToGetAllAuditFormula); //不会为空的
            if (dtOfAllFormula.Rows.Count == 0)
            {
                singleAuditOutCome += $"{auditFormulaTableNameInDB}不存在表内审核的公式!";
                // return singleAuditOutCome;
            }

            // sht.Cells[1, 1].Value = "审核原因说明(请勿在后面的列增加内容,有可能导致新旧审核结果过录失败)";
            string oneSingleAuditFormula = null;//本来在里面,为了记录日志提到外面来了
            string oneSingleAuditFormulaName = null;
            for (int i = 0; i < dtOfAllFormula.Rows.Count; i++)
            {
                try
                {
                    DataRow row = dtOfAllFormula.Rows[i];
                    //string oneSingleAuditFormula = row["sql语句"].ToString();
                    oneSingleAuditFormulaName = row["审核公式名称"].ToString();
                    oneSingleAuditFormula = row["sql语句"].ToString();
                    DataTable dtOfOneAuditFormulaOutcome =
                        auditOperator.GetDataTable(oneSingleAuditFormula);
                    if (dtOfOneAuditFormulaOutcome.Rows.Count != 0)
                    {
                        // 将审核结果写入Excel
                        //先写入审核公式

                        shtAuditOutcome.Cells[startRow, 2].Value = "类型:" + row["表间关系"].ToString();
                        shtAuditOutcome.Cells[startRow + 1, 2].Value = "严重度:" + row["严重度"].ToString();
                        shtAuditOutcome.Cells[startRow + 2, 2].Value = "审核公式:" + row["审核公式名称"].ToString();
                        shtAuditOutcome.Cells[startRow + 3, 2].Value = "说明:" + row["审核公式说明"].ToString();
                        if (row["严重度"].ToString().Contains("强制性"))
                        {
                            shtAuditOutcome.Cells[startRow, 2].Style.Font.Color.SetColor(Color.Red);
                            shtAuditOutcome.Cells[startRow + 1, 2].Style.Font.Color.SetColor(Color.Red);
                            shtAuditOutcome.Cells[startRow + 2, 2].Style.Font.Color.SetColor(Color.Red);
                            shtAuditOutcome.Cells[startRow + 3, 2].Style.Font.Color.SetColor(Color.Red);
                        }
                        else
                        {
                            shtAuditOutcome.Cells[startRow, 2].Style.Font.Color.SetColor(Color.Blue);
                            shtAuditOutcome.Cells[startRow + 1, 2].Style.Font.Color.SetColor(Color.Blue);
                            shtAuditOutcome.Cells[startRow + 2, 2].Style.Font.Color.SetColor(Color.Blue);
                            shtAuditOutcome.Cells[startRow + 3, 2].Style.Font.Color.SetColor(Color.Blue);
                        }

                        //先写入表头,即县\乡\村这些内容
                        for (int colCountOfdtOfOneAuditFormulaOutcome = 0;
                             colCountOfdtOfOneAuditFormulaOutcome < dtOfOneAuditFormulaOutcome.Columns.Count;
                             colCountOfdtOfOneAuditFormulaOutcome++)
                        {
                            shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2]
                                .Value = dtOfOneAuditFormulaOutcome
                                .Columns[colCountOfdtOfOneAuditFormulaOutcome].ColumnName;
                            shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style
                                .Font.Size = 12;
                            shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style.WrapText = true;
                            shtAuditOutcome.Cells[startRow + 4, colCountOfdtOfOneAuditFormulaOutcome + 2].Style.Font.Bold = true;
                            //shtAuditOutcome.Cells[startRow, colCountOfdtOfOneAuditFormulaOutcome + 2].Style.Font.Color 
                        }

                        //写入数据
                        for (int rowCountOfdtOfOneAuditFormulaOutcome = 0;
                             rowCountOfdtOfOneAuditFormulaOutcome < dtOfOneAuditFormulaOutcome.Rows.Count;
                             rowCountOfdtOfOneAuditFormulaOutcome++)
                        {
                            for (int colCountOfdtOfOneAuditFormulaOutcome = 0;
                                 colCountOfdtOfOneAuditFormulaOutcome <
                                 dtOfOneAuditFormulaOutcome.Columns.Count;
                                 colCountOfdtOfOneAuditFormulaOutcome++)
                            {
                                shtAuditOutcome.Cells[startRow + rowCountOfdtOfOneAuditFormulaOutcome + 5,
                                        colCountOfdtOfOneAuditFormulaOutcome + 2].Value =
                                    dtOfOneAuditFormulaOutcome.Rows[rowCountOfdtOfOneAuditFormulaOutcome][
                                        colCountOfdtOfOneAuditFormulaOutcome];
                            }
                        }

                        // 更新 startRow 为当前写入的最后一行的下一行
                        startRow += dtOfOneAuditFormulaOutcome.Rows.Count + 5;


                        // 写入表头
                        //for (int col = 0; col < dtOfOneAuditFormulaOutcome.Columns.Count; col++)
                        //{
                        //    shtAuditOutcome.Cells[1, col + 1].Value = dtOfOneAuditFormulaOutcome.Columns[col].ColumnName;
                        //}
                    }
                }
                catch (Exception ex)
                {
                    StaticLogger.SystemError($"执行{auditFormulaTableNameInDB}中的{oneSingleAuditFormulaName}公式时出错,错误信息为{ex.Message}");
                    auditOutcome.FuncOutComeInfoArgs += $"执行{auditFormulaTableNameInDB}中的{oneSingleAuditFormula}公式时出错,错误信息为{ex.Message}" + Environment.NewLine ;
                    auditOutcome.Icon = Icon.Warning;
                    continue;
                }
            }

            // return null;

        }

        private static string ConvertIntToStringOfSeason<T>(T IntSeason)
        {
            if (IntSeason is int intvalue)
            {
                if (intvalue == 1)
                {
                    return "第一季度";
                }
                else if (intvalue == 2)
                {
                    return "第二季度";
                }
                else if (intvalue == 3)
                {
                    return "第三季度";
                }
                else if (intvalue == 4)
                {
                    return "第四季度";
                }
                else
                {
                    return "输入整形参数错误";
                }
            }
            else if (IntSeason is string strValue)
            {
                if (strValue.Equals("1") || strValue.Equals("一"))
                {
                    return "第一季度";
                }
                else if (strValue.Equals("2") || strValue.Equals("二"))
                {
                    return "第二季度";
                }
                else if (strValue.Equals("3") || strValue.Equals("三"))
                {
                    return "第三季度";
                }
                else if (strValue.Equals("4") || strValue.Equals("四"))
                {
                    return "第四季度";
                }
                else
                {
                    return "输入字符串参数错误";
                }
            }
            else
            {
                return "数据类型错误";
            }
        }


        public static FuncOutCome DataComparison(int intYear, int intSeason, string[] allTableNames, out List<DataComparisonOutcome> List_dedicatedOutcome)
        {
            List_dedicatedOutcome = new List<DataComparisonOutcome>();
            FuncOutCome dataComparisonOutCome = new FuncOutCome();
            //根据传进来的年度和季度设置成表名称
            string strSeasonValue = ConvertIntToStringOfSeason<int>(intSeason);
            string unionTableName = $"一套表{intYear}年{strSeasonValue}";
            string statsCloudTableName = $"统计云{intYear}年{strSeasonValue}";
            //先确保所有的表都在
            // MyDBOperator myDBOperator = new MyDBOperator();改用单例模式
            MyDBOperator myDBOperator = MyDBOperator.DBOperatorInstance;


            foreach (string ATableName in allTableNames)
            {
                try
                {
                    string getUnionDatatable = null;
                    string getStatsCloudDatatable = null;
                    if (ATableName.Contains("A209"))
                    {
                        if (myDBOperator.CheckIfTableExists($"{unionTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{unionTableName}{ATableName}";
                            loseTableOutcome.ValueInOldPlat = "未导入";
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{unionTableName}{ATableName}未导入"+Environment.NewLine;
                            continue;
                        }
                        if (myDBOperator.CheckIfTableExists($"{statsCloudTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{statsCloudTableName}{ATableName}";
                            loseTableOutcome.ValueInStatsCloud = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{statsCloudTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        //getUnionDatatable = "select 县,乡,户编码,户主姓名,[期末存栏合计01],[25公斤以下仔猪02]," +
                        //                    $"[待育肥猪03],[50公斤以上04],[种猪05],[能繁殖母猪06],[当季增加头数07],[自繁08],[购进09],[当季减少头数10],[自宰肥猪头数11]," +
                        //                    $"[出售肥猪头数（不包括出售待育肥猪）12],[出售肥猪金额13],[出售肥猪重量14],[其它原因减少（包括死亡、疫病捕杀）15], " +
                        //                    $"[出售25公斤以下仔猪头数16],[出售25公斤以下仔猪金额17],[出售25公斤以下仔猪重量18]  from  {unionTableName}{ATableName}";
                        //getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,[期末存栏合计01],[25公斤以下仔猪02]," +
                        //                         $"[待育肥猪03],[50公斤以上04],[种猪05],[能繁殖母猪06],[当季增加头数07],[自繁08],[购进09],[当季减少头数10],[自宰肥猪头数11]," +
                        //                         $"[出售肥猪头数（不包括出售待育肥猪）12],[出售肥猪金额13],[出售肥猪重量14],[其它原因减少（包括死亡、疫病捕杀）15], " +
                        //                         $"[出售25公斤以下仔猪头数16],[出售25公斤以下仔猪金额17],[出售25公斤以下仔猪重量18]  from  {statsCloudTableName}{ATableName}";
                        getUnionDatatable = "select 县,乡,户编码,户主姓名,[期末存栏合计01],[25公斤以下仔猪存栏数02]," +
                                    $"[待育肥猪存栏数03],[50公斤以上待育肥猪存栏数04],[种猪存栏数05],[能繁殖母猪存栏数06],[当季增加头数07],[自繁头数08],[购进头数09],[当季减少头数10],[自宰肥猪头数11]," +
                                    $"[出售肥猪头数（不包括出售待育肥猪）12],[出售肥猪金额（元）13],[出售肥猪重量（公斤）14],[其它原因减少（包括死亡、疫病捕杀）15], " +
                                    $"[出售25公斤以下仔猪头数16],[出售25公斤以下仔猪金额（元）17],[出售25公斤以下仔猪重量（公斤）18]   from  {unionTableName}{ATableName}";
                        getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,[期末存栏合计01],[25公斤以下仔猪存栏数02]," +
                                    $"[待育肥猪存栏数03],[50公斤以上待育肥猪存栏数04],[种猪存栏数05],[能繁殖母猪存栏数06],[当季增加头数07],[自繁头数08],[购进头数09],[当季减少头数10],[自宰肥猪头数11]," +
                                    $"[出售肥猪头数（不包括出售待育肥猪）12],[出售肥猪金额（元）13],[出售肥猪重量（公斤）14],[其它原因减少（包括死亡、疫病捕杀）15], " +
                                    $"[出售25公斤以下仔猪头数16],[出售25公斤以下仔猪金额（元）17],[出售25公斤以下仔猪重量（公斤）18]   from  {statsCloudTableName}{ATableName}";
                    }
                    else if (ATableName.Contains("A210"))
                    {
                        if (myDBOperator.CheckIfTableExists($"{unionTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{unionTableName}{ATableName}";
                            loseTableOutcome.ValueInOldPlat = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{unionTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        if (myDBOperator.CheckIfTableExists($"{statsCloudTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{statsCloudTableName}{ATableName}";
                            loseTableOutcome.ValueInStatsCloud = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{statsCloudTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        //getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏头数01],[肉牛02]," +
                        //                    $"[能繁殖母牛03],[奶牛04],[在产奶牛05],[当季增加头数06],[自繁07],[肉牛08],[奶牛09],[购进10],[肉牛11]," +
                        //                    $"[奶牛12],[期内减少头数13],[自宰肉牛数量14],[出售肉牛数量15], " +
                        //                    $"[出售肉牛金额16],[出售肉牛重量17],[当季生牛奶产量18]  from  {unionTableName}{ATableName}";
                        //getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏头数01],[肉牛02]," +
                        //                         $"[能繁殖母牛03],[奶牛04],[在产奶牛05],[当季增加头数06],[自繁07],[肉牛08],[奶牛09],[购进10],[肉牛11]," +
                        //                         $"[奶牛12],[期内减少头数13],[自宰肉牛数量14],[出售肉牛数量15], " +
                        //                         $"[出售肉牛金额16],[出售肉牛重量17],[当季生牛奶产量18]   from  {statsCloudTableName}{ATableName}";
                        getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏头数01],[肉牛存栏数02]," +
                                    $"[能繁殖母牛存栏数03],[奶牛存栏数04],[在产奶牛存栏数05],[当季增加头数06],[自繁头数07],[自繁肉牛头数08],[自繁奶牛头数09],[购进头数10],[购进肉牛头数11]," +
                                    $"[购进奶牛头数12],[期内减少头数13],[自宰肉牛数量14],[出售肉牛数量15], " +
                                    $"[出售肉牛金额（元）16],[出售肉牛重量（公斤）17],[当季生牛奶产量（公斤）18]  from  {unionTableName}{ATableName}";
                        getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏头数01],[肉牛存栏数02]," +
                                    $"[能繁殖母牛存栏数03],[奶牛存栏数04],[在产奶牛存栏数05],[当季增加头数06],[自繁头数07],[自繁肉牛头数08],[自繁奶牛头数09],[购进头数10],[购进肉牛头数11]," +
                                    $"[购进奶牛头数12],[期内减少头数13],[自宰肉牛数量14],[出售肉牛数量15], " +
                                    $"[出售肉牛金额（元）16],[出售肉牛重量（公斤）17],[当季生牛奶产量（公斤）18]   from  {statsCloudTableName}{ATableName}";
                    }
                    else if (ATableName.Contains("A211"))
                    {
                        if (myDBOperator.CheckIfTableExists($"{unionTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{unionTableName}{ATableName}";
                            loseTableOutcome.ValueInOldPlat = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{unionTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        if (myDBOperator.CheckIfTableExists($"{statsCloudTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{statsCloudTableName}{ATableName}";
                            loseTableOutcome.ValueInStatsCloud = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{statsCloudTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        //getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[山   羊02]," +
                        //                    $"[能繁殖母山羊03],[绵(湖)羊04],[能繁殖母绵羊05],[期内增加只数06],[自繁07],[山   羊08],[绵(湖)羊09],[购进10],[山   羊11]," +
                        //                    $"[绵(湖)羊12],[期内减少只数13],[自宰羊数量14],[出售羊数量15], " +
                        //                    $"[出售羊金额16],[出售羊重量17],[当季绵羊毛产量18],[当季山羊绒产量19]  from  {unionTableName}{ATableName}";
                        //getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[山   羊02]," +
                        //                         $"[能繁殖母山羊03],[绵(湖)羊04],[能繁殖母绵羊05],[期内增加只数06],[自繁07],[山   羊08],[绵(湖)羊09],[购进10],[山   羊11]," +
                        //                         $"[绵(湖)羊12],[期内减少只数13],[自宰羊数量14],[出售羊数量15], " +
                        //                         $"[出售羊金额16],[出售羊重量17],[当季绵羊毛产量18],[当季山羊绒产量19]  from  {statsCloudTableName}{ATableName}";
                        getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[山羊存栏只数02]," +
                                    $"[能繁殖母山羊存栏只数03],[绵(湖)羊存栏只数04],[能繁殖母绵羊存栏只数05],[期内增加只数06],[自繁只数07],[山羊自繁只数08],[绵(湖)羊自繁只数09],[购进只数10],[山羊购进只数11]," +
                                    $"[绵(湖)羊购进只数12],[期内减少只数13],[自宰羊数量14],[出售羊数量15], " +
                                    $"[出售羊金额（元）16],[出售羊重量（公斤）17],[当季绵羊毛产量（公斤）18],[当季山羊绒产量（公斤）19]  from  {unionTableName}{ATableName}";
                        getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[山羊存栏只数02]," +
                                    $"[能繁殖母山羊存栏只数03],[绵(湖)羊存栏只数04],[能繁殖母绵羊存栏只数05],[期内增加只数06],[自繁只数07],[山羊自繁只数08],[绵(湖)羊自繁只数09],[购进只数10],[山羊购进只数11]," +
                                    $"[绵(湖)羊购进只数12],[期内减少只数13],[自宰羊数量14],[出售羊数量15], " +
                                    $"[出售羊金额（元）16],[出售羊重量（公斤）17],[当季绵羊毛产量（公斤）18],[当季山羊绒产量（公斤）19]  from  {statsCloudTableName}{ATableName}";
                    }
                    else if (ATableName.Contains("A212"))
                    {
                        if (myDBOperator.CheckIfTableExists($"{unionTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{unionTableName}{ATableName}";
                            loseTableOutcome.ValueInOldPlat = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{unionTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }
                        if (myDBOperator.CheckIfTableExists($"{statsCloudTableName}{ATableName}") == false)
                        {
                            DataComparisonOutcome loseTableOutcome = new DataComparisonOutcome();
                            loseTableOutcome.Indicator = $"{statsCloudTableName}{ATableName}";
                            loseTableOutcome.ValueInStatsCloud = "未导入";
                            dataComparisonOutCome.FuncOutComeInfoArgs += $"{statsCloudTableName}{ATableName}未导入"+Environment.NewLine;
                            List_dedicatedOutcome.Add(loseTableOutcome);
                            continue;
                        }

                        //getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[肉用02]," +
                        //                    $"[肉鸡03],[蛋用04],[蛋鸡05],[期内减少只数06],[自宰家禽数量07],[活鸡08],[出售家禽数量09],[活鸡10],[出售家禽金额11]," +
                        //                    $"[活鸡12],[出售家禽重量13],[活鸡14],[当季禽蛋产量15], [鸡蛋16]  from  {unionTableName}{ATableName}";
                        //getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[肉用02]," +
                        //                         $"[肉鸡03],[蛋用04],[蛋鸡05],[期内减少只数06],[自宰家禽数量07],[活鸡08],[出售家禽数量09],[活鸡10],[出售家禽金额11]," +
                        //                         $"[活鸡12],[出售家禽重量13],[活鸡14],[当季禽蛋产量15], [鸡蛋16]  from  {statsCloudTableName}{ATableName}";
                        getUnionDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[肉用家禽存栏只数02]," +
                                    $"[肉鸡存栏只数03],[蛋用家禽存栏只数04],[蛋鸡存栏只数05],[期内减少只数06],[自宰家禽数量07],[自宰活鸡数量08],[出售家禽数量09],[出售活鸡数量10],[出售家禽金额（元）11]," +
                                    $"[出售活鸡金额（元）12],[出售家禽重量（公斤）13],[出售活鸡重量（公斤）14],[当季禽蛋产量（公斤）15], [鸡蛋产量（公斤）16]  from  {unionTableName}{ATableName}";
                        getStatsCloudDatatable = "select 县,乡,户编码,户主姓名,养殖户单位类型,[期末存栏只数01],[肉用家禽存栏只数02]," +
                                    $"[肉鸡存栏只数03],[蛋用家禽存栏只数04],[蛋鸡存栏只数05],[期内减少只数06],[自宰家禽数量07],[自宰活鸡数量08],[出售家禽数量09],[出售活鸡数量10],[出售家禽金额（元）11]," +
                                    $"[出售活鸡金额（元）12],[出售家禽重量（公斤）13],[出售活鸡重量（公斤）14],[当季禽蛋产量（公斤）15], [鸡蛋产量（公斤）16]  from  {statsCloudTableName}{ATableName}";
                    }

                    DataTable dtOfUnion = myDBOperator.GetDataTable(getUnionDatatable);
                    DataTable dtOfStatsCloud = myDBOperator.GetDataTable(getStatsCloudDatatable);

                    if (dtOfUnion.Rows.Count != dtOfStatsCloud.Rows.Count)
                    {
                        DataComparisonOutcome dedicatedOutcome = new DataComparisonOutcome();
                        //await   MyMessagebox.ShowAsyncInMainWindow($"行数不一致,请确保统计云已经填报所有{ATableName}养殖户数据");
                        //comparisonOutcom += $"{ATableName}行数不一致,请确保统计云已经填报所有养殖户数据,然后本畜种重新审一遍" + Environment.NewLine;
                        dataComparisonOutCome.FuncOutComeInfoArgs +=
                            $"{ATableName}行数不一致,请确保统计云已经填报所有养殖户数据,然后本畜种重新审一遍" + Environment.NewLine;
                        dedicatedOutcome.Indicator = $"{ATableName}行数";
                        dedicatedOutcome.ValueInOldPlat = dtOfUnion.Rows.Count.ToString();
                        dedicatedOutcome.ValueInStatsCloud = dtOfStatsCloud.Rows.Count.ToString();
                        List_dedicatedOutcome.Add(dedicatedOutcome);
                        #region 算了,太麻烦了
                        //string[] allFarmingNamesInUnion = dtOfUnion.AsEnumerable()
                        //    .Select(row => row.Field<string>("户主姓名").ToString()).ToArray();
                        //string[] allFarmingNamesInStatsCloud = dtOfStatsCloud.AsEnumerable().Select(row => row.Field<string>("户主姓名").ToString()).ToArray();
                        //var onlyInUnion = allFarmingNamesInUnion.Except(allFarmingNamesInStatsCloud, StringComparer.OrdinalIgnoreCase).ToArray();
                        //var onlyInStatsCloud = allFarmingNamesInStatsCloud.Except(allFarmingNamesInUnion, StringComparer.OrdinalIgnoreCase).ToArray();

                        //var onlyInUnionRow = dtOfUnion.AsEnumerable()
                        //    .Where(row=>row.Field<string>("户主姓名")==)


                        //// 指定需要提取的列名
                        //string[] columnNames = { "县", "乡", "村", "户主姓名" };

                        //var farmingNamesInOldPlate = dtOfUnion.AsEnumerable()
                        //    .Select(row => columnNames.Select(col => new DataColumn(col, typeof(string))).ToArray());
                        #endregion

                        continue;
                    }
                    //for (int i = 0; i < dtOfUnion.Rows.Count; i++)
                    //{
                    //    DataRow row1 = dtOfUnion.Rows[i];
                    //    DataRow row2 = dtOfStatsCloud.Rows[i];

                    //    for (int j = 0; j < dtOfUnion.Columns.Count; j++)
                    //    {
                    //        if (!row1[j].Equals(row2[j]))
                    //        {
                    //            //await MyMessagebox.ShowAsyncInMainWindow($"统计云和一套表在{row1["户主姓名"].ToString()}的{dtOfUnion.Columns[j].ColumnName}指标不一致,统计云为{row1[j]},而一套表为{row2[j]}");
                    //            comparisonOutcom += $"统计云和一套表在{row1["户主姓名"].ToString()}的{dtOfUnion.Columns[j].ColumnName}指标不一致,统计云为{row1[j]},而一套表为{row2[j]}"+Environment.NewLine;

                    //        }
                    //    }
                    //}

                    for (int i = 0; i < dtOfUnion.Rows.Count; i++)
                    {
                        DataRow row1 = dtOfUnion.Rows[i];
                        string massCodeThisRowInDtOfUnion = row1["户编码"].ToString();
                        DataRow rowInDtOfStatsCloud = dtOfStatsCloud.Select($"户编码 = '{massCodeThisRowInDtOfUnion}'")[0];
                        for (int j = 0; j < dtOfUnion.Columns.Count; j++)
                        {
                            if (!row1[j].Equals(rowInDtOfStatsCloud[j]))
                            {
                                DataComparisonOutcome dedicatedOutcome = new DataComparisonOutcome();
                                string 错误信息 = row1[j].ToString();
                                string 错误信息2 = rowInDtOfStatsCloud[j].ToString();
                                // comparisonOutcom += $"统计云和一套表在{ATableName}{row1["乡"].ToString()}{row1["户主姓名"].ToString()}的“{dtOfUnion.Columns[j].ColumnName}”指标不一致,一套表为：{row1[j]},而统计云为：{rowInDtOfStatsCloud[j]}" +  Environment.NewLine;
                                dataComparisonOutCome.FuncOutComeInfoArgs +=
                                    $"统计云和一套表在{ATableName}{row1["乡"].ToString()}{row1["户主姓名"].ToString()}的“{dtOfUnion.Columns[j].ColumnName}”指标不一致,一套表为：{row1[j]},而统计云为：{rowInDtOfStatsCloud[j]}" +
                                    Environment.NewLine;
                                dedicatedOutcome.Country = row1["县"].ToString();
                                dedicatedOutcome.Town = row1["乡"].ToString();
                                dedicatedOutcome.FarmingName = row1["户主姓名"].ToString();
                                dedicatedOutcome.Indicator = dtOfUnion.Columns[j].ColumnName.ToString();
                                dedicatedOutcome.ValueInOldPlat = row1[j].ToString();
                                dedicatedOutcome.ValueInStatsCloud = rowInDtOfStatsCloud[j].ToString();
                                List_dedicatedOutcome.Add(dedicatedOutcome);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    StaticLogger.SystemError($"数据比对时出错,比对的表为{ATableName},错误信息为{ex.Message}");
                }
            }

            //await MyMessagebox.ShowAsyncInMainWindow("数据比较完毕",Icon.Success);
            // return comparisonOutcom;

            if (string.IsNullOrEmpty(dataComparisonOutCome.FuncOutComeInfoArgs) ==
                false) //如果结果对象的参数为空,说明没有没有遇到任何错误,否则有错误出现
            {
                dataComparisonOutCome.FuncSuccessCode = FuncOutComeCodeType.Error;
                dataComparisonOutCome.Icon = Icon.Warning;
                // dataComparisonOutCome.SomeOtherInfo = "一套表和统计云数据比对结束,存在错误,请查看文本框";

            }
            else
            {
                dataComparisonOutCome.FuncSuccessCode = FuncOutComeCodeType.Success;
                dataComparisonOutCome.Icon = Icon.Success;
                // dataComparisonOutCome.SomeOtherInfo = "一套表和统计云数据比对结束,没有发现错误!";

            }

            return dataComparisonOutCome;
            //首先比较
        }
    }
}